#!/bin/bash
# - testsuite
# - case

. $LKP_SRC/lib/upload.sh


prepare_test()
{      
       dnf install -y git
       git clone https://gitee.com/openeuler/mugen.git  $BENCHMARK_ROOT/test-mugen/mugen
       cd $BENCHMARK_ROOT/test-mugen/mugen || exit
}


dns_resolver()
{
	cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 223.5.5.5
EOF
}

set_env()
{
	export LANG="en_US.UTF-8"
	bash dep_install.sh 
	echo "direct_server_ips:$direct_server_ips, direct_client_1: $direct_client1_ips"
	echo $(env |grep "direct")
	bash mugen.sh -c --ip  $direct_server_ips --password $secrets_userpassword  --user $secrets_username --port 22 
	bash mugen.sh -c --ip  $direct_client1_ips --password $secrets_userpassword  --user $secrets_username --port 22
	bash mugen.sh -c --ip  $direct_client2_ips --password $secrets_userpassword  --user $secrets_username --port 22
}


test_one_case()
{
	bash mugen.sh  -f "$testsuite" -r "$case" -x
}

test_one_testsuite()
{
	bash mugen.sh -f "$testsuite" -x
}

test_all_cases()
{
	bash mugen.sh -a -x
}

upload_results_logs()
{
       ls results/"$testsuite"/failed >> results/failed_list
       ls results/"$testsuite"/succeed >> results/succeed_list
       upload_files -t logs logs/*
       upload_files -t results results/failed_list
       upload_files -t results results/succeed_list

}

run()
{
	prepare_test
	dns_resolver
	set_env
	if [ -n "$testsuite" ];then
		if [ -n "$case" ];then
			test_one_case
		else
			test_one_testsuite
		fi
	else
		test_all_cases
	fi
	upload_results_logs
}

run
